<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>海报贴图工具</title>

  <script th:src="@{/js/poster.js}" type="text/javascript"></script>

  <style>
    /* 通用样式 */

    /* 在小屏幕设备上应用的样式 */
    @media only screen and (max-width: 600px) {
      /* 小屏幕设备的样式 */
      body {
        font-size: 14px; /* 调整字体大小 */
      }

      #preview {
        width: 100%; /* 调整预览容器的宽度 */
        height: auto; /* 自适应高度 */
      }
    }
  </style>
</head>
<body>
<h1>海报贴图</h1>
<form id="uploadForm" action="#" th:action="@{/poster}" th:object="${posterForm}" method="post" enctype="multipart/form-data"
      onsubmit="return validateFileType()">
  <div class="container">
    <div class="row">
      <div class="col-lg-6 col-md-6 col-sm-12">
        <label for="type">海报类型：</label>
        <select id="type" name="type" th:field="*{type}" onchange="showImage(this)">
          <option value="" selected>请选择</option>
          <option th:each="option : ${options}"
                  th:value="${option.type}"
                  th:text="${option.name}"
                  th:data-image="${option.sourceImg}"
          />
        </select>
      </div>

      <div class="col-lg-6 col-md-6 col-sm-12">
        <div id="preview" style="width: 100%; height: 200px; overflow: hidden;">
          <img id="previewImage" src="" alt="海报预览" style="width: 100%; height: 100%; object-fit: contain;">
        </div>
      </div>
    </div>

    <div class="row">
      <div class="col-lg-12 col-md-12 col-sm-12">
        <label for="file">选择贴图：</label>
        <input type="file" id="file" name="file" onchange="showPreviewSelected(this)"/>

        <div id="previewImg" style="width: 100%; height: 100px; overflow: hidden;">
          <img id="previewImgImage" src="" alt="请选择贴图" style="width: 100%; height: 100%; object-fit: contain;">
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-lg-12 col-md-12 col-sm-12">
        <button type="submit">生成贴图</button>
      </div>
      <div id="display" style="width: 100%; height: 200px; overflow: hidden;">
        <img id="displayImage" src="#" alt="图片预览">
      </div>
    </div>
  </div>
</form>

</body>
</html>